#include<iostream>
#include<string>
#include<vector>
#include<sqlite3.h>

class SqliteHelper{
    public:
        typedef int (*sqliteCallback)(void *, int, char **, char **);
        SqliteHelper(const std::string &filename) : _dbfile(filename), _handler(nullptr) {}
        bool open(int safe_level = SQLITE_OPEN_FULLMUTEX){
            int ret = sqlite3_open_v2(_dbfile.c_str(), &_handler, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | safe_level, nullptr);
            if (ret == -1){
                
                return false;
            }
            return true;
        }
        bool exec(const std::string &sql, sqliteCallback cb, void *arg){
            int ret = sqlite3_exec(_handler, sql.c_str(), cb, arg, nullptr);
            if (ret == -1){
                return false;
            }
            return true;
        }
        void close(){
            if (_handler){
                sqlite3_close_v2(_handler);
            }
        }

    private:
        std::string _dbfile;
        sqlite3 *_handler;
};